<#-- API 服务模块：${functionName}相关接口 -->
import type { ${ClassName}<#if childrenTables?? && childrenTables?size gt 0><#list childrenTables as childTable>, ${childTable.ClassName}</#list></#if> } from "@/pages/${moduleName}/${businessName}/entity";
import apiClient from "../../apiClient";

<#-- 分页查询请求参数 -->
export interface PageListReq {
<#list columns as column>
    <#if column.isQuery()>
  //${column.columnComment}
  ${column.javaField}?: ${column.tsType};
    </#if>
</#list>
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

<#-- 分页查询响应数据 -->
export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: ${ClassName}[];
}

<#-- 分页查询 -->
const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/${moduleName}/${businessName}/pageList",
    data
});
<#if tplCategory == "tree">

<#-- 树型数据 -->
const treeList = (data: PageListReq): Promise<${ClassName}> =>
  apiClient.post({ url: "/${moduleName}/${businessName}/treeList", data });

</#if>
<#-- 获取详情 -->
const getInfo = (${table.pkColumn.javaField}: React.Key): Promise<${ClassName}> =>
  apiClient.get({
    url: `/${moduleName}/${businessName}/$${"{"}${table.pkColumn.javaField}${"}"}`
});

<#-- 新增数据 -->
const add = (data: ${ClassName}): Promise<${ClassName}> =>
  apiClient.post({
    url: "/${moduleName}/${businessName}",
    data
});

<#-- 更新数据 -->
const update = (data: ${ClassName}): Promise<${ClassName}> =>
  apiClient.put({
    url: "/${moduleName}/${businessName}",
    data
});

<#-- 删除数据 -->
const remove = (${table.pkColumn.javaField}s: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/${moduleName}/${businessName}",
    params: {
    ids: ${table.pkColumn.javaField}s.join(",")
  }
});
<#if childrenTables?? && childrenTables?size gt 0>
<#list childrenTables as childTable>
<#-- 根据父ID查询数据 -->
const get${childTable.businessName}s = (id: React.Key): Promise<${childTable.ClassName}[]> =>
  apiClient.post({
    url: "/${moduleName}/${childTable.businessName}/list",
    data: {
      ${childTable.parentId}: id
    }
  });

</#list>
</#if>
<#-- 导出API服务 -->
export const ${className}Service = {
  pageList,
<#if tplCategory == "tree">
  treeList,
</#if>
  getInfo,
  add,
  update,
  remove,
<#if childrenTables?? && childrenTables?size gt 0>
<#list childrenTables as childTable>
  get${childTable.businessName}s,
</#list>
</#if>
};

export default ${className}Service;